//
//  TBNavBottomView.m
//  Tourism
//
//  Created by 张亚 on 16/1/23.
//  Copyright © 2016年 zhikuiyu. All rights reserved.
//

#import "TBNavBottomView.h"

#define Width [UIScreen mainScreen].bounds.size.width

@interface TBNavBottomView ()
/**
 *  记录当前选中的按钮
 */
@property (nonatomic, weak) ZYButton *selectedButton;
@end

@implementation TBNavBottomView

- (id)initWithCoder:(NSCoder *)aDecoder{
    
    if(self = [super initWithCoder:aDecoder]){
        
    }
    return self;
    
}

-(UIButton *)addView{
    if (_addView == nil) {
        _addView = [ZYButton buttonWithType:UIButtonTypeCustom];
        _addView.frame = CGRectMake(0, 0, Width/4, self.frame.size.height);
        _addView.titleLabel.font = [UIFont systemFontOfSize:12];
        [_addView addTarget:self action:@selector(addBtnIsClick:) forControlEvents:UIControlEventTouchUpInside];
        [self addSubview:_addView];
    }
    return _addView;
}
- (UIButton *)twoView{
    if (_twoView == nil) {
        _twoView = [ZYButton buttonWithType:UIButtonTypeCustom];
        CGFloat btnX = Width/4;
        _twoView.frame = CGRectMake(btnX * 1, 0, Width/4, self.frame.size.height);
        _twoView.titleLabel.font = [UIFont systemFontOfSize:12];
        [_twoView addTarget:self action:@selector(twoBtnIsClick:) forControlEvents:UIControlEventTouchUpInside];
        [self addSubview:_twoView];
    }
    return _twoView;
}

-(UIButton *)thirdView{
    if (_thirdView == nil) {
        _thirdView = [ZYButton buttonWithType:UIButtonTypeCustom];
        CGFloat btnX = Width/4;
        _thirdView.frame = CGRectMake(btnX * 2, 0, Width/4, self.frame.size.height);
        _thirdView.titleLabel.font = [UIFont systemFontOfSize:12];
        [_thirdView addTarget:self action:@selector(thirdBtnIsClick) forControlEvents:UIControlEventTouchUpInside];
        [self addSubview:_thirdView];
    }
    return _thirdView;
}

-(UIButton *)fourView{
    if (_fourView == nil) {
        _fourView = [ZYButton buttonWithType:UIButtonTypeCustom];
        CGFloat btnX = Width/4;
        _fourView.frame = CGRectMake(btnX * 3, 0, Width/4, self.frame.size.height);
        
        _fourView.titleLabel.font = [UIFont systemFontOfSize:12];
        [_fourView addTarget:self action:@selector(fourBtnIsClick) forControlEvents:UIControlEventTouchUpInside];
        [self addSubview:_fourView];
    }
    return _fourView;
}

- (void)addBtnIsClick:(ZYButton *)button{
    if (_delegate && [_delegate respondsToSelector:@selector(navBottomAddBtnDidClick:)]) {
        [_delegate navBottomAddBtnDidClick:self];
    }
    //1.去掉之前按钮选中状态
    self.selectedButton.selected = NO;
    //2.让新的按钮选中
    button.selected = YES;
    //3.新点击按钮成为当前选中按钮
    self.selectedButton = button;
}
- (void)twoBtnIsClick:(ZYButton *)button{
    if (_delegate && [_delegate respondsToSelector:@selector(navBottomFormBtnDidClick:)]) {
        [_delegate navBottomFormBtnDidClick:self];
    }
    //1.去掉之前按钮选中状态
    self.selectedButton.selected = NO;
    //2.让新的按钮选中
    button.selected = YES;
    //3.新点击按钮成为当前选中按钮
    self.selectedButton = button;
}
- (void)thirdBtnIsClick{
    if (_delegate && [_delegate respondsToSelector:@selector(navBottomGuideBtnDidClick:)]) {
        [_delegate navBottomGuideBtnDidClick:self];
    }
}
- (void)fourBtnIsClick{
    if (_delegate && [_delegate respondsToSelector:@selector(navBottomConsultBtnDidClick:)]) {
        [_delegate navBottomConsultBtnDidClick:self];
    }
}



@end
